package resp

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func fail(ctx *gin.Context, code int, msg string) {
	ctx.JSON(200, resp{Code: code, Msg: msg})
}

func Fail(ctx *gin.Context, err error) {
	fail(ctx, -1, err.Error())
}

func Failf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -1, fmt.Sprintf(format, args...))
}

func FailAuth(ctx *gin.Context, err error) {
	fail(ctx, -901, err.Error())
}

func FailAuthf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -901, fmt.Sprintf(format, args...))
}

func FailPermission(ctx *gin.Context, err error) {
	fail(ctx, -801, err.Error())
}

func FailPermissionf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -801, fmt.Sprintf(format, args...))
}

func FailNet(ctx *gin.Context, err error) {
	fail(ctx, -301, err.Error())
}

func FailNetf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -301, fmt.Sprintf(format, args...))
}

func FailDB(ctx *gin.Context, err error) {
	fail(ctx, -201, err.Error())
}

func FailDBf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -201, fmt.Sprintf(format, args...))
}

func FailParam(ctx *gin.Context, err error) {
	fail(ctx, -101, err.Error())
}

func FailParamf(ctx *gin.Context, format string, args ...any) {
	fail(ctx, -101, fmt.Sprintf(format, args...))
}
